package cn.tedu._03vehicle.base.interceptors;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Slf4j
public class TimeAccessInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("进入限定访问时间拦截器");
        LocalDateTime now = LocalDateTime.now();
        int hour = now.getHour();
        if (hour >= 6 && hour < 23){
            return true;
        }else {
            throw new RuntimeException("只能在6：00-22：59时间进行访问！！");
        }
    }

}
